package com.me.study.javaCore.annotation;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.util.Arrays;

import static org.junit.Assert.*;

/**
 * 自定义注解测试类，用来学习自定义注解
 *
 * @author ME
 * @date 2019/10/13
 */
public class TestAnnotation {

    /**
     * 从 实体类上的注解获取 Table_Name，并生成 Insert语句
     */
    @Test
    public void test1() {
        City city = new City();
        city.setId("1");
        city.setName("TZ");
        System.out.println(CommonUtil.buildQuerySqlForEntity(city) + "\n");
    }

    /**
     * 获取注解的注解
     */
    @Test
    public void test2() {
        Class<City> clazz = City.class;
        System.out.println("City.class 的类信息：" + clazz);
        assertTrue("此类型上存在指定注解", clazz.isAnnotationPresent(MyEntity.class));

        MyEntity myEntity = clazz.getAnnotation(MyEntity.class);
        System.out.println("@MyEntity 对象：" + myEntity);
        Class<? extends Annotation> type = myEntity.annotationType();
        System.out.println("@MyEntity 的类信息：" + type);

        System.out.println("@MyEntity 的 value值：" + myEntity.value());
        System.out.println("\n@MyEntity 上的元注解：");
        Arrays.stream(type.getDeclaredAnnotations()).forEach(System.out::println);
    }

}
